﻿        var map, layer,drawBox,boxLayer,
        url = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World",
        styleTest1 = {
                fill:false,
                strokeColor:"blue"
            },
         styleTest2 = {
                fill:false,
                strokeColor:"red"
            };
        function init(){

            boxLayer = new SuperMap.Layer.Vector("boxLayer");
            polygonLayer = new SuperMap.Layer.Vector("polygonLayer");

            boxLayer.style = styleTest1;
            polygonLayer.style =styleTest2;
            
            drawBox = new SuperMap.Control.DrawFeature(boxLayer,SuperMap.Handler.Box);
            drawPolygon = new SuperMap.Control.DrawFeature(polygonLayer,SuperMap.Handler.Polygon);
                      
            map = new SuperMap.Map("map",{controls:[
                new SuperMap.Control.Zoom() ,
                new SuperMap.Control.Navigation() ,
                new SuperMap.Control.LayerSwitcher()
            ,drawBox,drawPolygon]});

            layer = new SuperMap.Layer.TiledDynamicRESTLayer("World",url,null,{maxResolution:"auto"});
            
            layer.events.on({"layerInitialized":addLayer});
               
            drawBox.events.on({"featureadded":drawBoxCompleted});
            drawPolygon.events.on({"featureadded":drawPolygonCompleted});
            
        }

        function addLayer(){
            map.addLayers([layer,boxLayer,polygonLayer]);
            map.setCenter(new SuperMap.LonLat(0,0),0);
        }

        function drawBoxCompleted(eventArgs){
            var geometry1 = eventArgs.feature.geometry;
            var bounds1 = geometry1.bounds.toArray();
            
            alert(bounds1);
        }

        function drawPolygonCompleted(eventArgs){
            var geometry2 = eventArgs.feature.geometry;
            var vertices = geometry2.getVertices();
            var bounds2 = geometry2.bounds.toArray();

            alert(vertices+'\n'+bounds2);
        }

        function draw_box(){
            deactiveAll();
            drawBox.activate();
        }

        function draw_polygon(){
            deactiveAll();
            drawPolygon.activate();
        }

        function deactiveAll(){
            drawPolygon.deactivate();
            drawBox.deactivate();
        }

        function clearFeatures(){
            boxLayer.removeAllFeatures();
            polygonLayer.removeAllFeatures();
        }